package com.example.score.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.score.entity.ScoreStatistics;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

@Mapper
public interface ScoreStatisticsMapper extends BaseMapper<ScoreStatistics> {
    
    @Insert("<script>" +
            "INSERT INTO t_score_statistics (exam_detail_id, class_id, class_name, " +
            "total_students, submit_students, full_score, max_score, avg_score, " +
            "median_score, std_dev, excellent_count, excellent_rate, pass_count, " +
            "pass_rate, objective_avg_score, subjective_avg_score, created_time, updated_time) VALUES " +
            "<foreach collection='list' item='item' separator=','>" +
            "(#{item.examDetailId}, #{item.classId}, #{item.className}, " +
            "#{item.totalStudents}, #{item.submitStudents}, #{item.fullScore}, " +
            "#{item.maxScore}, #{item.avgScore}, #{item.medianScore}, #{item.stdDev}, " +
            "#{item.excellentCount}, #{item.excellentRate}, #{item.passCount}, " +
            "#{item.passRate}, #{item.objectiveAvgScore}, #{item.subjectiveAvgScore}, " +
            "now(), now())" +
            "</foreach>" +
            "</script>")
    void insertBatch(@Param("list") List<ScoreStatistics> statistics);

    @Select("SELECT * FROM t_score_statistics WHERE exam_detail_id = #{examDetailId}")
    List<ScoreStatistics> selectByExamDetailId(@Param("examDetailId") Long examDetailId);

    @Select("SELECT * FROM t_score_statistics WHERE exam_detail_id = #{examDetailId} AND class_id = #{classId}")
    ScoreStatistics selectByExamDetailIdAndClassId(@Param("examDetailId") Long examDetailId, @Param("classId") Long classId);

    List<Map<String, Object>> getWrongQuestions(@Param("examDetailId") Long examDetailId);
}
 